/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package persistencia;

import dto.Alumno;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.sql.*;

/**
 *
 * @author Hades
 */
public class AlumnoDAO {

    public String bd = "alumnos1";
    public String login = "root";
    public String password = "root";
    public String url = "jdbc:mysql://localhost/" + bd;

    public void updateAlumnoById(Alumno alumno) {
        try {
            Connection conexion = null;

            // registro de drive
            try {
                Class.forName("org.gjt.mm.mysql.Driver");
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(AlumnoDAO.class.getName()).log(Level.SEVERE, null, ex);
            }

            conexion = DriverManager.getConnection(url, login, password);

            String query1 = "update alumno set nombre='" + alumno.getNombre() + "'," + "apellidoPaterno='" + alumno.getApellidoPaterno() + "'," + "apellidoMaterno='" + alumno.getApellidoMaterno() + "'," + "edad=" + alumno.getEdad() + ",semestre=" + alumno.getSemestre() + "," + "idCarrera=" + alumno.getIdCarrera() + "," + "direccion=" + "\"" + alumno.getDireccion() + "\"" + "where control='" + alumno.getControl() + "'";
            Statement st = conexion.createStatement();
            //ejecutamos el query 
            st.executeUpdate(query1);
            //Siempre hay que cerrar la conexion
            st.close();

        } catch (SQLException ex) {
            System.out.println(ex + "Hubo un problema al intentar conectarse"
                    + "con la base de datos" + url);

        }
	
	
    }

    public void deleteAlumnoById(Alumno alumno) {
        try {
            Connection conexion = null;

            // registro de drive
            try {
                Class.forName("org.gjt.mm.mysql.Driver");
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(AlumnoDAO.class.getName()).log(Level.SEVERE, null, ex);
            }

            conexion = DriverManager.getConnection(url, login, password);

            String query1 = "delete from alumno where control='" + alumno.getControl() + "'";
            Statement st = conexion.createStatement();
            //ejecutamos el query 
            st.executeUpdate(query1);
            //Siempre hay que cerrar la conexion
            st.close();

        } catch (SQLException ex) {
            System.out.println(ex + "Hubo un problema al intentar conectarse"
                    + "con la base de datos" + url);

        }



    }
}
